package d0326;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static javafx.scene.input.KeyCode.V;
import static javafx.scene.input.KeyCode.Y;

public class TestHashMap {
    public static void main(String[] args) {
        Map<String, Student> studentMap = new HashMap<>();

        Student s1 = new Student("胡儿", 10, 92);
        Student s2 = new Student("胡孙", 15, 82);
        Student s3 = new Student("饼儿", 14, 53);
        Student s4 = new Student("饼孙", 11, 74);

        studentMap.put("he", s1);
        studentMap.put("hs", s2);
        studentMap.put("be", s3);
        studentMap.put("be", s4);
        studentMap.put("huer", s1);
        studentMap.put("huer", s1);//重复的key会被忽略

        System.out.println(studentMap.size());
        //key不同，value可以相同
        Student x1 = studentMap.get("he");
        System.out.println(x1);

        Set<String> keys = studentMap.keySet();
        for (String str :
                keys) {
            System.out.println(str + "--" + studentMap.get(str));
        }

        System.out.println("=============================");

        //key可以取得value，反过来不行
        Collection<Student> values = studentMap.values();
        for (Student str1 :
                values) {
            System.out.println(str1);
        }
        System.out.println("===================================");
        Set<Map.Entry<String, Student>> entys = studentMap.entrySet();
        for (Map.Entry entry :
                entys) {
            System.out.println(entry.getKey() + "-->" + entry.getValue());
        }
       /* System.out.println("======================================");
        studentMap.forEach(K, V) -> {
        System.out.println(K + "----" + V);
    });*/
    }
}
